home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10439 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: castle.nando.net!news
  2. From: actuary@nando.net   (Bill McCarthy)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Converting Strings to Upper Case
  5. Date: 17 Mar 1996 21:54:57 GMT
  6. Organization: Nando.net Public Access
  7. Message-ID: <4ii1nh$bng@castle.nando.net>
  8. References: <4ifra6$52i@scipio.cyberstore.ca> <DoFA24.AL7@iquest.net>
  9. Reply-To: actuary@nando.net (Bill McCarthy)
  10. NNTP-Posting-Host: grail814.nando.net
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <DoFA24.AL7@iquest.net>, dlmiller@iquest.net (Doug & Rose Miller) writes:
  14. >ejw@news.cyberstore.ca () wrote:
  15. >+Hi,
  16. >+
  17. >+I need to write a function to convert a string containg upper or lower case
  18. >+characters to the opposite case.  Something like:
  19. >+
  20. >+  void libConvertUpperCase(char *str);    and
  21. >+  void libConvertLowerCase(char *str);
  22. >+
  23. >+and the string would be modified.  I just can't seem to wrap my head around
  24. >+the best way that I know is better than writing a for loop to check each
  25. >+element in the array?
  26. >+
  27. >+I apologize if this in the FAQ;  I am still going thorugh it.  Any help
  28. >+would be greatly appreciated.
  29. >+
  30. >+Eric Woodward.
  31. >+ejw@cyberstore.ca.
  32. >+
  33. >
  34. >
  35. >#include <stdio.h>
  36. >
  37. >void main (void) {
  38.  
  39. Oh, please!  Read the FAQ to avoid posting crap like this.
  40.  
  41. >char    test[] = "aBcDeFgHiJkLmNoPqRsTuVwXyZ";
  42. >char    *p;
  43. >
  44. >printf ("%s\n", &test);
  45.  
  46. &test ???  How about just test?
  47.  
  48. >for (p = test; *p; *p++)
  49.  
  50. And what do you think you are accomplishing with *p++ that p++ or ++p
  51. wouldn't do???
  52.  
  53. >    if (isalpha(*p)) *p ^= 0x20;  /* for ascii machines e.g. PC; use 0x40 for ebcdic machines e.g. IBM mainframe */
  54.  
  55. isalpha() has not been declared.  It takes an int and *p may be a signed
  56. char, how about *(unsigned char *)p.  Also, your code is toggling between
  57. upper and lower case.
  58.  
  59. >printf ("%s\n", &test);
  60.  
  61. There you go again with this &test thingy.  Finally, you'll want a
  62. "return 0;" after you've fixed the "void main" error.
  63.  
  64. >}
  65.  
  66. Bill McCarthy
  67. actuary@nando.net
  68. Wendell, NC  USA
  69.  
  70.